use anyhow::Result;
use cluster_node_manager::{ClusterManager, Config};
use tracing::{info, Level};
use tracing_subscriber;

/// Simple example demonstrating basic cluster setup
#[tokio::main]
async fn main() -> Result<()> {
    // Initialize logging
    tracing_subscriber::fmt()
        .with_max_level(Level::INFO)
        .init();

    info!("Starting simple cluster example");

    // Create default configuration
    let mut config = Config::default();
    config.node.id = 1;
    config.node.bind_addr = "127.0.0.1:8001".to_string();
    config.cluster.name = "simple-cluster".to_string();
    config.api.bind_addr = "127.0.0.1:8080".to_string();

    // Create cluster manager
    let cluster_manager = ClusterManager::new(config).await?;

    // Initialize as single-node cluster
    cluster_manager.initialize_cluster().await?;

    // Start the cluster
    cluster_manager.start().await?;

    info!("Cluster started successfully!");
    info!("API server running on http://127.0.0.1:8080");
    info!("Metrics available at http://127.0.0.1:9090/metrics");

    // Keep running until Ctrl+C
    tokio::signal::ctrl_c().await?;

    info!("Shutting down cluster");
    cluster_manager.shutdown().await?;

    Ok(())
}
